Dedicated analog-to-digital (A/D) converters are known in the art. These converters offer high speed and resolution, but they are relatively expensive. Many A/D applications do not require high speed or resolution. For instance, many automotive applications such as potentiometer settings for light-dimmers, fuel-level indicators, signal converters for temperature and pressure sensors, and battery-voltage indicators do not experience rapid voltage variations with time, nor do they require high resolution voltage readings. Thus, for these applications and many others, low cost A/D converters have been proposed.
It is known in the art to use a high speed CMOS microcontroller to achieve an eight bit A/D conversion in approximately 10 ms. This technique is based on the fact that if a repetitive waveform is applied to an RC network, the capacitor will charge to the average voltage, provided that the RC time constant of the RC network is much larger than the pulse widths in the repetitive waveform. The rate at which pulses are applied to the capacitor is adjusted until the voltage on the capacitor matches the input voltage being measured. The basic equation for computing the A/D result is: EQU Vin=Vref[Ton/(Ton+Toff)] (1)
Where Ton and Toff are the amount of time the waveform is at its high and low voltages, respectively.
To achieve the desired resolution with this approach, it is necessary to precisely measure several Ton and Toff time periods. In addition, the waveform must be gradually adjusted to allow for the large RC time constant to settle out. This results in a relatively long conversion cycle. Better results are obtained by averaging several pulses over a fixed period of time and using the following equation: EQU Vin=Vref[Sum of Ton/(Sum of (Ton+Toff)] (2)
FIG. 1 depicts a microcontroller based A/D converter 10. The A/D converter 10 utilizes a National Semiconductor COP822C microcontroller 12, a low cost LM2901 comparator 14, 2 100K resistors 16, and a 0.01 microfarads film capacitor 18. The microcontroller 12 provides a squarewave signal 20. The squarewave signal 20 includes an "off" pulse 21 with a logic level very close to ground and an "on" pulse 23 with a logic level very close to Vref. The signal generates a small ramp voltage on the capacitor for the inverting input of the comparator 14.
To minimize error, a tradeoff is made when selecting the resistors 16. The microcontroller output 22 should have a large resistor 16A to minimize the output switching offset, and the comparator should have a small resistor 16B due to error caused by input bias offset current. In this embodiment, a 100 k resistor 16A is used in the RC network for one comparator 14 input. Therefore, another 100 k resistor 16B is required for the Vin input to balance the offset voltage caused by the comparator input bias current.
Once the resistor sizes are determined, the capacitor 18 should be chosen so that the RC time constant is large enough to provide a small incremental voltage ramp. This design has a sample time of 20 microseconds and has a 1 millisecond RC time constant with a 0.01 mfd film capacitor 18 which has low leakage current to prevent errors.
Turning to FIG. 2, a prior art approach to programming the microcontroller 12 of FIG. 1 is depicted. By way of overview, 768 ("on" or "off") pulses are applied by the microcontroller 12 to the comparator 14 through capacitor 18. A third of the pulses (256) are used to charge the capacitor 18 so that it is approximately equal with Vin. Thereafter, a positive pulse is applied by microcontroller 12 to capacitor 18 when Vc drops below Vin. This equalizing of the voltage on the capacitor, Vc, with the input voltage, Vin, continues for the remaining number of pulses. After the remaining pulses have been applied, equation 2 is used to calculate Vin.
More specifically, the prior art approach works as follows. A program is stored within the memory of microcontroller 12. This program corresponds to the instruction set of FIG. 2. First, the total number of pulse counts, for instance 768, is loaded, and the same value is assigned to the variable Ton, which designates the number of "on" pulses applied by the microcontroller 12 (block 30). Next, the output from the comparator 14 is sampled (block 32). If the output from the comparator 14 is ZERO, then the voltage on the capacitor, Vc, is larger than the input voltage, Vin. To equalize the voltages, a negative pulse ("off" pulse) is applied by the microcontroller (block 34). In addition, the Ton value is decremented by one; that is, the Ton value was loaded assuming all pulses would be positive; therefore, the Ton value must be decremented. The period for both "on" and "off" pulses is equivalent.
If the output from the comparator 14 is ONE, then the voltage on the capacitor, Vc, is smaller than the input voltage, Vin. To equalize the voltages, a positive pulse is applied by the microcontroller (block 38). In this instance, a delay is applied by the microcontroller (block 40) in order to equalize the time with the opposite loop (blocks 34 and 36).
Thereafter, the counter is decremented (block 42) to indicate that another pulse has been processed. If the total number of pulses has been reduced to 512 (decision block 44), then the capacitor is initialized; that is, one third of the pulses have been applied and the capacitor is roughly set to Vin. At this juncture, Ton is reset to 512 to indicate the remaining loops or pulse counts to be processed (block 46).
If the total number of pulses does not equal 512 (decision block 44), then a determination is made as to whether the total count of pulses is equal to zero (decision block 48). If the total count has not been reduced to zero, then the pulse processing continues until a total of 768 pulses have been processed. Once all pulses have been processed, the value of Ton is used in equation (2) to calculate Vin (block 50). Thus, in the example provided, the value of Ton will be divided by 512 and multiplied by Vref to determine Vin. Alternately, the eight bit value obtained by dividing Ton by two represents the input voltage, in binary form.
While this prior art solution provides an efficient and inexpensive A/D conversion, there are still a number of problems associated with it. First, the accuracy of the conversion may be improved. Next, the comparator 14 generally requires a 2 volt supply voltage above its input range. Thus, with a 5 volt supply, the actual input range of the comparator 14 is only 3 volts.